package com.itwn.service;

import com.itwn.entity.Manager;
import com.itwn.mapper.ManagerMapper;
import com.itwn.vo.PermissionVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.itwn.entity.ManagerRole;
import com.itwn.mapper.ManagerRoleMapper;
import com.itwn.vo.ManagerVo;
import java.util.Date;
import java.util.List;

@Service
public class ManagerService {
    @Autowired
    ManagerMapper managerMapper;
    public PageInfo<ManagerVo> queryAllManager(String userName,String userCode, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<ManagerVo> managerList = managerMapper.findAllManager(userName,userCode);
        return new PageInfo<>(managerList);
    }

    public int addManager(ManagerVo managerVo) {
        int i = managerMapper.insert(managerVo);
            return i;
    }

    public Manager findByPrimaryKey(String userCode){
        return managerMapper.selectByPrimaryKey(userCode);
    }

    public int addRole(Long managerId, Long roleId, Date insertTime, Date updateTime){
            return managerMapper.insertManagerRole(managerId,roleId,insertTime,updateTime);
    }

    public int modifyManager(ManagerVo managerVo) {
        return managerMapper.updateManager(managerVo);
    }

    public int removeManagerRole(Long id,Long roleCode) {
        return managerMapper.deleteManagerRoel(id,roleCode);
    }

    public int removeById(Long id) {
        return managerMapper.deleteById(id);
    }

    @Autowired
    ManagerRoleMapper managerRoleMapper;
    public List<ManagerRole> queryManagerRole(Long id) {
        return managerRoleMapper.selectById(id);
    }

    public int removeManagerRoleById(Long id) {
        return managerRoleMapper.deleteByPrimaryKey(id);
    }


    public Manager findByCode(String code){
        Manager manager = managerMapper.selectByCode(code);
        return manager;
    }

    public List<PermissionVo> findPermissionByCode(String userCode) {
        List<PermissionVo> voList = managerMapper.selectPermissionByCode(userCode);
        return voList;
}
}
